package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.model.common.app.pojo.ApUserInfo;
import com.zhentao.model.common.dtos.ResponseResult;
import com.zhentao.model.common.enums.AppHttpCodeEnum;
import com.zhentao.service.ApUserInfoService;
import com.zhentao.mapper.ApUserInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 薄超轩
* @description 针对表【ap_user_info】的数据库操作Service实现
* @createDate 2024-09-27 14:20:00
*/
@Service
public class ApUserInfoServiceImpl extends ServiceImpl<ApUserInfoMapper, ApUserInfo>
    implements ApUserInfoService{
    @Resource
    private ApUserInfoMapper apUserInfoMapper;

    @Override
    public ResponseResult addUserInfo(ApUserInfo apUserInfo) {
        if(apUserInfo.getId()==null){
            apUserInfoMapper.insert(apUserInfo);
            return ResponseResult.okResult("操作成功");
        }else {
            apUserInfoMapper.updateById(apUserInfo);
            return ResponseResult.okResult("修改成功");
        }
    }

    @Override
    public ResponseResult getUserInfo(Integer id) {
        if (id==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        QueryWrapper<ApUserInfo>wrapper=new QueryWrapper<>();
        wrapper.lambda().eq(ApUserInfo::getUid, id);
        ApUserInfo apUserInfo = apUserInfoMapper.selectOne(wrapper);
        return ResponseResult.okResult(apUserInfo);
    }

    @Override
    public ResponseResult findUsersBySex(ApUserInfo apUserInfo) {
        QueryWrapper<ApUserInfo>wrapper=new QueryWrapper<>();
        wrapper.lambda().eq(apUserInfo.getSex()!=null,ApUserInfo::getSex, apUserInfo.getSex());
        wrapper.lambda().eq(apUserInfo.getAge()!=null, ApUserInfo::getAge, apUserInfo.getAge());
        wrapper.lambda().eq(apUserInfo.getHeight()!=null , ApUserInfo::getHeight, apUserInfo.getHeight());
        wrapper.lambda().eq(StringUtils.isNotBlank(apUserInfo.getEducational()), ApUserInfo::getEducational, apUserInfo.getEducational());
        wrapper.lambda().eq(apUserInfo.getIncome()!=null, ApUserInfo::getIncome, apUserInfo.getIncome());
        List<ApUserInfo> apUserInfos = apUserInfoMapper.selectList(wrapper);
        return ResponseResult.okResult(apUserInfos);
    }


}




